package string;

/**
 * Created with IntelliJ IDEA.
 * Description: 459.重复的子字符串
 * User: Li_yizYa
 * Date: 2025—04—16
 * Time: 20:33
 */
public class Solution6 {
    public static void main(String[] args) {
        String s1 = "abab";
        String s2 = "ababababababc";
        System.out.println(repeatedSubstringPattern(s1) + "+" + repeatedSubstringPattern(s2));
    }
    // a b a b
    //     i
    //       j
    private static boolean repeatedSubstringPattern(String s) {
        int len = s.length();
        for (int i = 1; i <= len / 2; i++) {
            boolean match = true;
            for (int j = i; j < len; j++) {
                if (s.charAt(j) != s.charAt(j - i)) {
                    match = false;
                    break;
                }
            }
            if (match) {
                return true;
            }
        }
        return false;
    }
}
